package com.tpay.client.presenter;

import com.google.inject.Inject;
import com.google.web.bindery.event.shared.EventBus;
import com.gwtplatform.mvp.client.proxy.Gatekeeper;
import com.tpay.client.CurrentUser;
import com.tpay.client.event.LoginAuthenticatedEvent;
import com.tpay.client.event.LoginAuthenticatedEventHandler;

public class AdminGatekeeper implements Gatekeeper {
	private final EventBus eventBus;
	private CurrentUser currentUser;
	
	@Inject
	public AdminGatekeeper(final EventBus eventBus) {
		this.eventBus = eventBus;
		
		this.eventBus.addHandler(LoginAuthenticatedEvent.getType(), new LoginAuthenticatedEventHandler() {
			@Override
			public void onLoginAuthenticated(LoginAuthenticatedEvent event) {
				currentUser = event.getCurrentUser();				
			}
		});
	}
	
	@Override
	public boolean canReveal() {
		boolean administrator = false;
		
		if(currentUser != null)
			administrator = currentUser.isAdministrator();
		
		return administrator;
	}

}
